Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 24, 2025

Problem

The invoice.upcoming webhook event was failing with the error:

Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.

This occurred because upcoming invoices from Stripe don't have an id field, causing the Firestore document path to be invalid when trying to create the invoice document.

Root Cause

In the insertInvoiceRecord function in utils.ts, the code was attempting to use invoice.id directly as the Firestore document ID:

await customersSnap.docs[0].ref
  .collection('subscriptions')
  .doc(invoice.subscription as string)
  .collection('invoices')
  .doc(invoice.id)  // ❌ This is null/undefined for upcoming invoices
  .set(invoice);

For invoice.upcoming events, Stripe doesn't provide an id field since these are preview/draft invoices that haven't been finalized yet.

Solution

The fix generates a unique document ID for upcoming invoices when invoice.id is null/undefined:

// For upcoming invoices, generate a unique document ID since they don't have an id
const invoiceDocId = invoice.id || `upcoming_${invoice.subscription}_${Date.now()}`;

await customersSnap.docs[0].ref
  .collection('subscriptions')
  .doc(invoice.subscription as string)
  .collection('invoices')
  .doc(invoiceDocId)  // ✅ Always a valid string
  .set(invoice);

Additionally, the fix prevents creating unnecessary payment records for upcoming invoices when they don't have a payment intent, since upcoming invoices are previews and don't represent actual payments:

// Only create payment records for invoices that have a payment_intent or id
// Upcoming invoices are previews and don't represent actual payments
const recordId: string = (invoice.payment_intent as string) ?? invoice.id;
if (recordId) {
  // Create payment record only if recordId exists
  await customersSnap.docs[0].ref
    .collection('payments')
    .doc(recordId)
    .set({ prices }, { merge: true });
}

Impact

  • ✅ Fixes webhook processing for invoice.upcoming events
  • ✅ Preserves existing behavior for regular invoices with IDs
  • ✅ Prevents unnecessary payment records for preview invoices
  • ✅ Maintains unique document IDs using subscription + timestamp
  • ✅ No breaking changes to existing functionality

Test Cases Handled

  1. Regular invoice with ID: Uses original ID as document ID, creates payment record
  2. Upcoming invoice without ID: Generates unique ID (upcoming_{subscription}_{timestamp}), skips payment record if no payment_intent
  3. Invoice without ID but with payment_intent: Generates unique ID, creates payment record using payment_intent

Fixes #616


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…out id

Co-authored-by: Ehesp <842078+Ehesp@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Can you investigte issue 616 and provide a fix Fix invoice.upcoming webhook handler failure - generate unique document ID for invoices without id Jul 24, 2025
@Copilot Copilot AI requested a review from Ehesp July 24, 2025 15:30
Copilot finished work on behalf of Ehesp July 24, 2025 15:30
Copy link

@Turbo-tenant Turbo-tenant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Form Name: Landlord Onboarding – Listing Setup
Campaign: turbotenant-landlord-onboarding

Form Fields

  • Full Name (required)
  • Email Address (required)
  • Phone Number
  • Password (min 8 characters)
  • Confirm Password
  • Property Address (required)
  • City / State / ZIP
  • Type of Property (Apartment, House, Condo)
  • Monthly Rent
  • Available From Date
  • Upload Property Photos

Form Settings

php-template
Copy code

Hidden Tracking Fields

  • utm_campaign=property_setup_flow
  • utm_source=landing_page
  • integration_source=turbotenant.com/onboard

🌐 Frontend / HTML Configuration

Below is the core front-end entry HTML for the TurboTenant onboarding and dashboard environment.
This integrates Google Tag Manager, Branch.io analytics, Google Fonts, and the TurboTenant PWA setup.

import pypandoc

Markdown content combining the webhook setup and TurboTenant welcome email

markdown_content = """

🔗 TurboTenant Landlord Onboarding + Stripe Webhook Integration

Webhook Configuration

Event Source: Connected and v2 accounts
Payload Format: Thin
API Version: Unversioned
Events Subscribed: 15
Destination Name: TurboTenant Landlord Onboarding

Endpoint URL:
https://www.turbotenant.com/api/webhooks/stripe (replace with your actual webhook URL)

Description:
Handles essential Stripe events related to landlord onboarding, payment setup, and property listing flows within TurboTenant.


Email Configuration

Sender Name: TurboTenant Support
From: no-reply@turbotenant-landlord-onboardin.firebaseapp.com
Reply-To: support@turbotenant.com

This setup ensures the verification email is delivered with clear sender info and directs any replies to your actual support inbox.


🏡 Welcome to TurboTenant!

Built by landlords, for landlords — TurboTenant makes it easy to find qualified tenants for free in just a few clicks.

🏠 Create Your Listing

If you’ve already started, you’re ahead of the game! If not, it’s quick to set up — just add your photos, description, amenities, and rent amount to make your listing stand out.

🚀 Advertise with One Click

Save time by instantly posting your rental across top property sites like Rent.com, Apartments.com, Realtor.com, and more.

📥 Manage Leads Effortlessly

You’ll receive an email whenever someone is interested in your property. Each lead completes an automatic pre-screening questionnaire, helping you track all your prospects in one place.

📝 Invite Qualified Renters to Apply

Once you find the right renter, invite them to apply directly through TurboTenant — it’s free for landlords! Every application includes a full industry-standard screening report.


MANAGE MY LISTING

⭐️ Want faster reviews and top-tier site visibility?
Upgrade to our Premium Subscription for priority placement and enhanced exposure.


📚 Resources for Landlords

Every successful landlord knows that knowledge is power. Explore our free learning resources:


📱 Manage Rentals Anywhere

Stay connected anywhere with the TurboTenant Mobile App — download today!

🎁 Give $25, Get $25!
Know someone who could use TurboTenant? Refer them today and you’ll both earn $25.


Support

Need help? Visit our Help Center or email our Colorado-based support team at support@turbotenant.com.


TurboTenant, Inc © 2025
320 E Vine Dr., Fort Collins, CO 80524

Manage Email Preferences | Unsubscribe
Terms of Service | Privacy Policy


🔗 Login Link for Internal Review

TurboTenant Login Dashboard

"""

Save as a .md file

output_path = "/mnt/data/turbotenant-landlord-onboarding.md"
with open(output_path, "w", encoding="utf-8") as f:
f.write(markdown_content)

output_path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invoice.upcoming failed: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.

4 participants